#!/usr/bin/env node

const EventEmitter = require('events');

// util 的 inherits 方法
function inherits(ctor, superCtor) {
  ctor.super_ = superCtor;
  ctor.prototype = Object.create(superCtor.prototype, {
    constructor: {
      value: ctor,
      enumerable: false,
      writable: true,
      configurable: true,
    },
  });
}

// Radio 类
function Radio(station) {
  if (!(this instanceof Radio)) {
    return new Radio(station);
  }
  EventEmitter.call(this);
  this.station = station;
  setTimeout(() => {
    this.emit('play', this.station);
  }, 0);
  setTimeout(() => {
    this.emit('stop', this.station);
  }, 5000);
}

inherits(Radio, EventEmitter);

module.exports = Radio;